//
//  MyArtLineViewController.m
//  Village
//
//  Created by longrise on 2017/10/18.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "MyArtLineViewController.h"
#import "HeadlineDetailsView.h"
#import "VillageModel.h"

@interface MyArtLineViewController ()
@property (nonatomic, strong) VillageModel *model;
@property (nonatomic, strong) HeadlineDetailsView *headView;
@end

@implementation MyArtLineViewController

- (void)setParams:(id)obj block:(LongriseRouterBlock)block
{
    self.model = (VillageModel *)obj;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"村头条";
    
    [self set_NavItem];
    
    [self config_UI];
}

- (void)config_UI
{
    self.headView = [[HeadlineDetailsView alloc] init];
    self.headView.model = self.model;
    [self.scroll addSubview:self.headView];
    [self.headView.iconImg sd_setImageWithURL:[NSURL URLWithString:[Globle getInstance].headImg.length > 0 ? [Globle getInstance].headImg : [Globle getInstance].visitorIcon] placeholderImage:[UIImage imageNamed:@"user_icon"]];
   self.headView.nameLab.text = [Globle getInstance].account.nickname.length > 0 ? [Globle getInstance].account.nickname : [Globle getInstance].account.account;
    self.headView.sd_layout
    .leftSpaceToView(self.scroll, 0)
    .topSpaceToView(self.scroll, 0)
    .rightSpaceToView(self.scroll, 0);
    
    [self.scroll setupAutoContentSizeWithBottomView:self.headView bottomMargin:20];
}


#pragma mark - 设置导航栏左右按钮
- (void)set_NavItem
{
    UIButton *rightbtn = [[UIButton alloc] initWithFrame:CGRectMake(0,0,20,4)];
    [rightbtn setImage:[UIImage imageNamed:@"share_details"] forState:UIControlStateNormal];
    rightbtn.titleLabel.font = LRFont(15);
    rightbtn.titleEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
    [rightbtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightbtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (void)rightBtnClick
{
    [ShareFunction shareInstance].titles = self.model.title;
    [ShareFunction shareInstance].content = self.model.content;
    [ShareFunction shareInstance].iconImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[Tools resolutionHeadImage:self.model.upimg]]]];
    [ShareFunction shareInstance].url = self.model.shareurl;
    [[ShareFunction shareInstance] shareToController:self];
}

@end
